package com.bom.core.util.poi;

import com.deepoove.poi.XWPFTemplate;
import com.deepoove.poi.config.Configure;
import com.deepoove.poi.policy.LoopColumnTableRenderPolicy;
import lombok.experimental.UtilityClass;

import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Arrays;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;

@UtilityClass
public class Pois {
    public static void main(String[] args) throws IOException {
        Object[] stand = {"规划条件", "R居住用地", 5.5, 0.4, 0.2, 3, 30, 1231};

        List<LinkedHashMap<Object, Object>> objs = Stream.of(
                //0,1,3,4,5,6,7
                new Object[]{"方案1", "R居住用地1", 6, 10, 0.2, 3, 42, 1231},
                new Object[]{"方案2", "R居住用地2", 4, 0.3, 0.2, 3, 31, 1231},
                new Object[]{"方案3", "R居住用地3", 3, 0.3, 0.2, 3, 33, 1231},
                new Object[]{"方案4", "R居住用地", 0, 0, 0, 0, 0, 0},
                stand
        ).map(e -> {
            final int[] count = {0};
            LinkedHashMap<Object, Object> map = new LinkedHashMap<>();
            Arrays.stream(e).forEach(v -> {
                Object value;
                if (count[0] == 0) {
                    value = v;
                } else if (count[0] == 1) {//不同类型
                    if (v.equals(stand[count[0]])) {
                        value = v;// Texts.of(v.toString()).color("FF5733").create();
                    } else {
                        value = v;
                    }
                } else {//其他类型

                    if (Double.parseDouble(v + "") > Double.parseDouble(stand[count[0]] + "")) {
                        value = Double.parseDouble(v + "");//Texts.of(v.toString()).color("FF5733").create();
                    } else {
                        value = Double.parseDouble(v + "");
                    }
                }
                map.put(count[0], value);
                count[0]++;
            });
            return map;
        }).collect(Collectors.toList());
        LinkedHashMap<Object, Object> oob = new LinkedHashMap<>();
        for (int i = 0; i < objs.size(); i++) {
            oob.put(i, objs.get(i));
        }
        LoopColumnTableRenderPolicy policy = new LoopColumnTableRenderPolicy();

        Configure config = Configure.builder().bind("objs", policy).build();
        XWPFTemplate template = XWPFTemplate.compile("C:\\Users\\Administrator\\Desktop\\XXX项目设计方案审查报告模板(1).docx", config).render(
                new HashMap<String, Object>() {{
                    put("objs", oob);
                }}
        );
        template.writeAndClose(new FileOutputStream("C:\\Users\\Administrator\\Desktop\\output.docx"));
    }
}
